package com.t216.dm216.wrapper;

import com.baomidou.mybatisplus.core.toolkit.support.SFunction;
import com.github.yulichang.wrapper.MPJLambdaWrapper;

public class DmMPJLambdaWrapper<T> extends MPJLambdaWrapper<T> {
    public DmMPJLambdaWrapper() {
    }

    public DmMPJLambdaWrapper(Class<T> clazz) {
        super(clazz);
    }

    @Override
    public <R> MPJLambdaWrapper<T> eqIfExists(SFunction<R, ?> column, Object val) {
        //0 != null true 直接执行了
        if (val != null) {
            if (val instanceof String) {
                if (val.toString().length() != 0) {
                    return super.eq(column, val);
                }
            }else if (val instanceof Integer) {
                Integer integer = (Integer)val;
                if (integer.intValue() != 0) {
                    return super.eq(column, integer);
                }
            }else if(val instanceof Long) {
                Long longVal = (Long)val;
                if (longVal.longValue() != 0) {
                    return super.eq(column, longVal);
                }
            }
        }
        return this;
    }


    public <R> MPJLambdaWrapper<T> likeIfExists(SFunction<R, ?> column, Object val) {
        if (val != null && val.toString().length() != 0) {
            return super.like(column, val);
        }
        return this;
    }
}
